<template>
  <div>
    <div style="text-align: center;">
      <span class="normalTitle">将</span>
      <span class="boldTitle"> {{ className }} </span>
      <span class="normalTitle">中的</span>
      <span class="boldTitle" v-for="(item, index) in studentName" :key="index"> {{ item }} </span>
      <span class="normalTitle">调整到指定教学班中</span>
    </div>
    <el-table
      ref="multipleTable"
      border
      :data="tableData"
      class="xpaas-table-class"
      row-class-name="xpaas-row-class"
      cell-class-name="xpaas-cell-class"
      header-row-class-name="xpaas-header-row-class"
      header-cell-class-name="xpaas-header-cell-class"
      @select="handleSelectionChange"
      style="margin: 15px 0;">
      <el-table-column type="selection" label="选择" width="60" align="center" />
      <el-table-column prop="classname" label="教学班" align="center" />
      <el-table-column prop="coursenumber" label="课程编号" align="center" />
      <el-table-column prop="coursename" label="课程名称" align="center" />
      <el-table-column prop="mainemployeeids" label="主讲教员" align="center" />
      <el-table-column prop="sktime" label="上课时间" align="center" />
      <el-table-column prop="skplace" label="上课地点" align="center" />
      <el-table-column label="选课要求" show-overflow-tooltip align="center">
        <template slot-scope="scoped">
          <span v-if="scoped.row.pyccxz !== '无限制' && scoped.row.pyccxz !== ''">{{scoped.row.pyccxz}}，</span>
          <span v-if="scoped.row.bxxz !== '无限制' && scoped.row.bxxz !== ''">{{scoped.row.bxxz}}，</span>
          <span v-if="scoped.row.xbxz !== '无限制' && scoped.row.xbxz !== ''">{{scoped.row.xbxz}}</span>
        </template>
      </el-table-column>
      <el-table-column label="额定/最大预选人数" align="center">
        <template slot-scope="scoped">
          <span>{{scoped.row.reservenum}}/</span>
          <span>{{scoped.row.maxnum}}</span>
        </template>
      </el-table-column>
      <el-table-column label="预选/正选人数" align="center">
        <template slot-scope="scoped">
          <span>{{scoped.row.preselectionnum}}</span>/
          <span>{{scoped.row.positivenum}}</span>
        </template>
      </el-table-column>
    </el-table>
    <div style="display: flex; flex-direction: row-reverse; padding-bottom: 15px;">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        style="padding: 0;">
      </el-pagination>
    </div>
    <div style="display: flex; justify-content: center;">
      <div class="button-style" style="background: #FFF6F0; border: 1px solid #E9B535;" @click="handleSubmit">
        <span style="color: #E9B535;">转&nbsp;入</span>
      </div>
      <div class="button-style" style="margin-left: 50px; background: #FFEEEF; border: 1px solid #FA533C;" @click="handleCancel">
        <span style="color: #FA533C;">取&nbsp;消</span>
      </div>
    </div>
  </div>
</template>

<script>
import { xxkkkgl_query_list, updateStudents } from '@/api/trainingManagement/place.js'
export default {
  data() {
    return {
      selectedRows: this.$route.query.selectedRows,
      total: 0,
      pageSize: 10,
      currentPage: 1,
      tableData: [],
      className: '',
      studentName: [],
      selectedRows1: []
    }
  },
  mounted() {
    if (this.selectedRows !== undefined && this.selectedRows.length > 0) {
      this.className = this.selectedRows[0].className
      this.selectedRows.forEach(item => {
        this.studentName.push(item.studentname)
      })
      this.handleSearch()
    } else {
      this.$message.warning('学员信息丢失！')
    }
  },
  methods: {
    handleSearch: function () {
      const current = this.currentPage
      const size = this.pageSize
      xxkkkgl_query_list("", "", "", "", "", "", "", "", "", current, size).then(res => {
        if (res.data.code === 200) {
          this.tableData = res.data.data.records
          this.total = res.data.data.total
        }
      })
    },
    handleSelectionChange: function (val) {
      this.selectedRows1 = val
    },
    handleSubmit: function () {
      if (this.selectedRows1.length > 0) {
        if (this.selectedRows1.length > 1) {
          this.$message.warning('只能选择一个教学班！')
        } else {
          const params = []
          this.selectedRows.forEach(item => {
            params.push({
              id: item.id,
              classno: this.selectedRows1[0].classno
            })
          })
          updateStudents(params).then(res => {
            if (res.data.code === 200) {
              this.handleSearch()
              this.$message.success('转教学班成功！')
            } else {
              this.$message.warning('转教学班失败！')
            }
          })
        }
      } else {
        this.$message.warning('请选择教学班！')
      }
    },
    handleCancel: function () {
      this.$store.dispatch('tagsView/delView', this.$route)
      this.$router.push('/admin/elective/adjustmentStudents')
    },
    handleCurrentChange: function (val) {
      this.currentPage = val
      this.handleSearch()
    },
    handleSizeChange: function (val) {
      this.pageSize = val
      this.handleSearch()
    }
  }
}
</script>

<style scoped lang="less">
  .button-style {
    float: left;
    background: #f1f8fe;
    border: 1px solid #51aef6;
    width: auto;
    height: 28px;
    line-height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    flex-wrap: nowrap;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 3px 10px;
    box-sizing: border-box;
    > span {
      font-size: 14px;
      color: #51aef6;
    }
  }
  @fontFamily:"Microsoft YaHei";
  .xpaas-table-class {
    border: 1px solid #004ca7;
    border-radius: 9px;
    ::v-deep div.el-table__header-wrapper {
      table.el-table__header {
        thead {
          tr.xpaas-header-row-class {
            padding: 0;
            height: 60px;
            background-color: #edf2f9;
            font-size: 16px;
            font-family: @fontFamily;
            font-weight: bold;
            line-height: 20px;
            color: #004ca7;
            th.xpaas-header-cell-class {
              font-weight: bold;
              border-right: 1px solid #c7d7eb;
              border-left: 0;
              border-bottom: 1px solid #c7d7eb;
              background-color: #edf2f9;
              div.cell {
                font-size: 16px;
                font-weight: bold;
                font-family: @fontFamily;
                color: #004ca7;
              }
            }
          }
        }
      }
    }
    ::v-deep div.el-table__body-wrapper {
      table.el-table__body {
        tbody {
          tr.xpaas-row-class {
            td.xpaas-header-cell-class {
              border-right: 1px solid #c7d7eb;
              border-left: 0;
              border-bottom: 1px solid #c7d7eb;
              background-color: #edf2f9;
              div.cell {
                font-size: 16px;
                font-weight: bold;
                font-family: @fontFamily;
                color: #004ca7;
              }
            }
            td.xpaas-cell-class {
              height: 60px;
              border-right: 1px solid #c7d7eb;
              border-left: 0;
              border-bottom: 1px solid #c7d7eb;
              div.cell {
                font-family: @fontFamily;
                color: #004ca7;
              }
            }
          }
        }
      }
    }
  }
  .normalTitle {
    font-size: 18px;
    color: #004ca7;
  }
  .boldTitle {
    font-size: 18px;
    font-weight: 600;
    color: #004ca7;
  }
</style>
